import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  strict:true,  // 开启严格模式  确保state 中的数据只能 mutations 修改
  state:{
    courseInfo:{
      courseName:'',
      courseIndex:'',
      sectionContent:'',
      label:'',
    },
    user:{
      userName:'',
      sex:'',
      userTel:'',
      userPassword:'',
      userEmail:'',
      schoolName:'',
      userHead:'',
      studentCollege:'',
      studentClassGrade:'',
      studentClassMajor:'',
      studentClassNumber:'',
      studentClassIndex:'',
    },
    discussinfo:{
      courseTalkTitle:'',
      courseTalkNumber:'',
      userName:'',
      gmtCreate:'',
      great:'',
      userHead:'',
      courseTalkContent:''
    },
    userId:'',
    questionSortId:'',
    questionId:'',
  },
  mutations:{
    updateCourseName(state,payload){
      state.courseInfo.courseName=payload.courseName
      // console.log(course)
      state.courseInfo.courseIndex=payload.courseIndex
      // console.log(index)
      console.log(state.courseInfo.courseIndex)
      localStorage.setItem('courseName',state.courseInfo.courseName)
      localStorage.setItem('courseIndex',state.courseInfo.courseIndex)
    },
    updateUser(state,payload){
      state.user.userName=payload.userName
      state.user.sex=payload.userGender
      state.user.userTel=payload.userTel
      state.user.userPassword=payload.userPassword
      state.user.userEmail=payload.userEmail
      state.user.schoolName=payload.schoolName
      state.user.userHead=payload.userHead
      state.user.studentCollege=payload.studentCollege
      state.user.studentClassGrade=payload.studentClassGrade
      state.user.studentClassMajor=payload.studentClassMajor
      state.user.studentClassNumber=payload.studentClassNumber
      state.user.studentClassIndex=payload.studentClassIndex
      localStorage.setItem('schoolName',state.user.schoolName)
      localStorage.setItem('userName',state.user.userName)
      localStorage.setItem('sex',state.user.sex)
      localStorage.setItem('userTel',state.user.userTel)
      localStorage.setItem('userPassword',state.user.userPassword)
      localStorage.setItem('userEmail',state.user.userEmail)
      localStorage.setItem('userHead', state.user.userHead)
      localStorage.setItem('studentCollege',state.user.studentCollege)
      localStorage.setItem('studentClassGrade',state.user.studentClassGrade)
      localStorage.setItem('studentClassMajor',state.user.studentClassMajor)
      localStorage.setItem('studentClassNumber',state.user.studentClassNumber)
      localStorage.setItem('studentClassIndex',state.user.studentClassIndex)
    },
    updateuserId(state,userId){
      state.userId=userId
      localStorage.setItem('userId',state.userId)
    },
    updatediscussInfo(state,payload){
      state.discussinfo.courseTalkNumber=payload.courseTalkNumber
      state.discussinfo.courseTalkTitle=payload.courseTalkTitle
      state.discussinfo.userName=payload.userName
      state.discussinfo.great=payload.great
      state.discussinfo.gmtCreate=payload.gmtCreate
      state.discussinfo.userHead=payload.userHead
      state.discussinfo.courseTalkContent=payload.courseTalkContent
      localStorage.setItem('DcourseTalkNumber',state.discussinfo.courseTalkNumber)
      localStorage.setItem('DcourseTalkTitle',state.discussinfo.courseTalkTitle)
      localStorage.setItem('DuserName',state.discussinfo.userName)
      localStorage.setItem('Dgreat',state.discussinfo.great)
      localStorage.setItem('DgmtCreate',state.discussinfo.gmtCreate)
      localStorage.setItem('DuserHead',state.discussinfo.userHead)
      localStorage.setItem('DcourseTalkContent',state.discussinfo.courseTalkContent)
    },
    updatesection(state,payload){
      state.courseInfo.sectionContent=payload.sectionContent
      state.courseInfo.label=payload.label
      localStorage.setItem('sectionContent',state.courseInfo.sectionContent)
      localStorage.setItem('label',state.courseInfo.label)
    },
    updateSortId(state,questionSortId){
      state.questionSortId=questionSortId
      localStorage.setItem('questionSortId',state.questionSortId)
    },
    updateQuestionId(state,questionId){
      state.questionId=questionId
      localStorage.setItem('questionId',state.questionId)
    }
  }
})

export default store;
